-- Ft

-- TODO:
-- 蘑菇林支线 背景房间为大量蘑菇树
-- 
for k,v in pairs{
	evergreen_short = 1,
	evergreen_normal = 1.5,
	evergreen_tall  = 2,
}do
	RG_AddPrefabPostInit(k, function(inst)
		if GetWorld().prefab == "rg_foresttrail" then
			inst.AnimState:SetScale(1.2, 1.2)
			inst.Physics:SetCapsule(v, 2)
			inst.components.workable:SetOnFinishCallback(nil)
			inst.components.workable:SetWorkLeft((v-0.5)*20)
		end
	end)
end

local function KeepTargetFn(inst, target)
	if inst.sg:HasStateTag("exit") then return false end
	if inst.sg:HasStateTag("hidden") then return true end
    if target then
        return not target.components.health:IsDead() and inst.components.combat:CanTarget(target)
    end
end

RG_AddPrefabPostInit("birchnutdrake", function(inst)
	inst.components.combat:SetKeepTargetFunction(KeepTargetFn)
end)

local level = RG_AddLevel{
	id="RG_FORESTTRAIL",
	name="Forest Trail Level",
	desc="",
	overrides={
		{"start_setpeice",  "rg_craftAspear"},
		{"start_node",    	"Clearing"},
		{"day",             "onlyday"},
		{"world_size",      "tiny"},

		-- line
		{"branching",        "never"},
		{"loop",             "never"},
	},
	
	tasks = {
		"RG_Ft_1",
		"RG_Ft_2",
		"RG_Ft_3",
		"RG_Ft_4",
		"RG_Ft_5",
		"RG_Ft_6",
		"RG_Ft_7",
		"RG_Ft_8",
	},

	numoptionaltasks = 0,
	optionaltasks = {},
	set_pieces = {},
	ordered_story_setpieces = {},
	required_prefabs = {},
	background_node_range = {10, 20},
	blocker_blank_room_name = "RG_Ft_DeepForest",
}

local data = {
	RG_Ft_1 = {
		-- room = "SpiderMarsh",
		room = "BrokenAltar",
		room_bg = GROUND.DIRT,
	},
	RG_Ft_2 = {
		room = "RG_Ft_Berry",
		room_bg = GROUND.FOREST,
	},
	RG_Ft_3 = {
		room = "RG_Ft_DeepForest",
		room_bg = GROUND.FOREST,
	},
	RG_Ft_4 = {
		room = "BeefalowPlain",
		room_bg = GROUND.GRASS,
	},
	RG_Ft_5 = {
		room = "SlightlyMermySwamp",
		room_bg = GROUND.DIRT,
	},
	RG_Ft_6 = {
		room = "RG_Ft_Mushrooms",
		room_bg = GROUND.GRASS
	},
	RG_Ft_7 = {
		room = "Rocky",
		room_bg = GROUND.DIRT
	},
	RG_Ft_8 = {
		room = "Rocky",
		room_bg = GROUND.DIRT
	},
}

for k,v in pairs(data)do
	RG_AddTask(k, {
		locks = LOCKS.NONE,
		keys_given = KEYS.NONE,
		room_choices = {[v.room] = 1},
		room_bg = v.room_bg,
		entrance_room = v.entrance_room,
		background_room = v.background_room or "RG_Ft_DeepForest",
	})
end


local Layouts = GLOBAL.require("map/layouts").Layouts
local StaticLayout = GLOBAL.require("map/static_layout")

local function landmark(opts)
	local o = opts or {}
	o.fill_mask = GLOBAL.PLACE_MASK.IGNORE_IMPASSABLE_BARREN_RESERVED
	o.layout_position = GLOBAL.LAYOUT_POSITION.CENTER
	return o
end

local randgen = randgen

RegisterLandmark("rg_craftAspear")

RegisterLayout("rg_3_berries_normal", {src = "rg_3_berries", defs = {slot = {"berrybush"}}})
RegisterLayout("rg_3_berries_special", {src = "rg_3_berries", defs = {slot = {"berrybush2"}}})
RegisterLayout("rg_3_berries_random", {src = "rg_3_berries", defs = {slot = {"berrybush", "berrybush2"}}})

Layouts["rg_1_berry_empty"] = {
	type = LAYOUT.STATIC,
	defs = {slot = {"berrybush", "berrybush2"}},
	layout = {slot = {{x = 0, y = 0, properties = PROPERTIES.barren()}}},
}


-- Give your layout an in-code name and point it to the exported file
Layouts["ChildLayout"] = StaticLayout.Get("map/static_layouts/child")
Layouts["Camp2Layout"] = StaticLayout.Get("map/static_layouts/camp2", landmark())
Layouts["Camp3Layout"] = StaticLayout.Get("map/static_layouts/camp3", landmark())
Layouts["Camp4Layout"] = StaticLayout.Get("map/static_layouts/camp4", landmark())
Layouts["TouristBloodLayout"] = StaticLayout.Get("map/static_layouts/tourist_blood", landmark())
Layouts["Tourist1Layout"] = StaticLayout.Get("map/static_layouts/tourist_1", landmark())
Layouts["Tourist2Layout"] = StaticLayout.Get("map/static_layouts/tourist_2", landmark())
Layouts["BigrockLayout"] = StaticLayout.Get("map/static_layouts/bigrock", landmark())
Layouts["Camp5Layout"] = StaticLayout.Get("map/static_layouts/camp5", landmark())
Layouts["Minicamp1"] = StaticLayout.Get("map/static_layouts/minicamp_1")
Layouts["Minicamp2"] = StaticLayout.Get("map/static_layouts/minicamp_2")
Layouts["Minicamp3"] = StaticLayout.Get("map/static_layouts/minicamp_3")
Layouts["Minicamp4"] = StaticLayout.Get("map/static_layouts/minicamp_4")
Layouts["Minicamp5"] = StaticLayout.Get("map/static_layouts/minicamp_5")
Layouts["Minicamp6"] = StaticLayout.Get("map/static_layouts/minicamp_6")

Layouts["RadioLayout"] = StaticLayout.Get("map/static_layouts/singular_item", landmark({defs={item={"radio_stand"}}}))
--Layouts["Sign_Campsite"] = StaticLayout.Get("map/static_layouts/singular_item", landmark({defs={item={"sign_campsite"}}}))
--Layouts["Sign_To_Totem"] = StaticLayout.Get("map/static_layouts/singular_item", landmark({defs={item={"sign_to_totem"}}}))
--Layouts["Sign_To_Scoutcamp"] = StaticLayout.Get("map/static_layouts/singular_item", landmark({defs={item={"sign_to_scoutcamp"}}}))
--Layouts["Sign_To_Bigrock"] = StaticLayout.Get("map/static_layouts/singular_item", landmark({defs={item={"sign_to_bigrock"}}}))
--Layouts["Sign_To_Ritual"] = StaticLayout.Get("map/static_layouts/singular_item", landmark({defs={item={"sign_to_ritual"}}}))

local GROUND = GROUND

GLOBAL.require("map/level") -- for LEVELTYPE

-- Make sure our new doodads don't spawn on the roads
GLOBAL.require("map/terrain")

GLOBAL.terrain.filter["evergreen_tall"] = {GROUND.ROAD}
GLOBAL.terrain.filter["ground_grass"] = {GROUND.ROAD}

-- How many loot containers in each room
local NUM_LOOT_CONTAINERS_PER_ROOM = 0--function() if math.random() > 0.75 then return 2 else return 1 end end


-- 背景房间，森林地皮，大量常青树
RG_AddRoom("RG_Ft_DeepForest", {
	type = "background",
	value = GROUND.FOREST,
	contents = {
		distributepercent = 1,
		distributeprefabs = {
			evergreen_short = 1,
			evergreen_normal = 2,
			evergreen_tall = 4,
		},
	},
})

-- 采集浆果
RG_AddRoom("RG_Ft_Berry", {
	value = GROUND.GRASS,
	contents = {
		countstaticlayouts = {
			rg_3_berries_random = 1,
			rg_1_berry_empty = randgen(2,4),
		},
		countprefabs = {
			spider = randgen(3,5),
			spider_warrior = 1,
		},
	}
})

-- 只有蜘蛛
RG_AddRoom("RG_Ft_Spider_3", {
	value = GROUND.FOREST,
	contents = {
		countprefabs = {
			spider = 3,
		},
	}
})

RG_AddRoom("RG_Ft_Spider_4", {
	value = GROUND.FOREST,
	contents = {
		countprefabs = {
			spider = 4,
		}
	}
})

RG_AddRoom("RG_Ft_Mushrooms", {
	value = GROUND.GRASS,
	contents = {
		countprefabs = {
			red_mushroom = randgen(1,2),
			green_mushroom = randgen(1,2),
			blue_mushroom = randgen(1,2),
			birchnutdrake = randgen(4,5),
		},
	},
})

----------------------------------------------------------------------------------------
-- BLOCKERS ----------------------------------------------------------------------------
----------------------------------------------------------------------------------------

----------------------------------------------------------------------------------------
-- LANDMARKS AND CAMPSITES -------------------------------------------------------------
----------------------------------------------------------------------------------------

AddRoom("Camp1_to_2_Room", {
	value = GROUND.GRASS,
	tags={"ForceConnected"},
	contents = {
		countstaticlayouts = {
			Camp1_to_2Layout = 1
		},
		countprefabs = {
			heli_sign = 1,
		},
		distributepercent = 1.0,
		distributeprefabs = {
			ground_grass=4,
			--evergreen=1,
			--berrybush=0.2,
			--sapling=0.2,
			--houndbone=0.01,
			--pond=0.01,
		},
	},
	colour = {r=1.0,g=0.5,b=1.0,a=0.25},
})
AddRoom("Camp2_Room", {
	value = GROUND.FOREST,
	tags={"ForceConnected"},
	contents = {
		countstaticlayouts = {
			Camp2Layout = 1
		},
		countprefabs = {
			heli_sign = 1,
		},
		distributepercent = 1.0,
		distributeprefabs = {
			ground_grass=4,
			--evergreen_sparse=1,
			--berrybush=0.2,
			--sapling=0.2,
			--houndbone=0.01,
		},
	},
	colour = {r=0.5,g=1.0,b=0.5,a=0.25},
})

AddRoom("Camp2_to_3_Room", {
	value = GROUND.GRASS,
	tags={"ForceConnected"},
	contents = {
		countstaticlayouts = {
			Camp2_to_3Layout = 1
		},
		countprefabs = {
			heli_sign = 1,
		},
		distributepercent = 1.0,
		distributeprefabs = {
			ground_grass=4,
			--evergreen=1,
			--berrybush=0.2,
			--sapling=0.2,
			--houndbone=0.01,
			--pond=0.01,
		},
	},
	colour = {r=0.5,g=1.0,b=1.0,a=0.25},
})
AddRoom("Camp3_Room", {
	value = GROUND.FOREST,
	tags={"ForceConnected"},
	contents = {
		countstaticlayouts = {
			Camp3Layout = 1
		},
		countprefabs = {
			heli_sign = 1,
		},
		distributepercent = 1.0,
		distributeprefabs = {
			ground_grass=4,
			--evergreen=1,
			--berrybush=0.2,
			--sapling=0.2,
			--houndbone=0.01,
			--pond=0.01,
		},
	},
	colour = {r=0.5,g=0.5,b=1.0,a=0.25},
})

AddRoom("Camp3_to_4_Room", {
	value = GROUND.GRASS,
	tags={"ForceConnected"},
	contents = {
		countstaticlayouts = {
			--Camp3_to_4Layout = 1
		},
		distributepercent = 1.0,
		distributeprefabs = {
			ground_grass=4,
			--evergreen=1,
			--berrybush=0.2,
			--sapling=0.2,
			--houndbone=0.01,
			--pond=0.01,
		},
	},
	colour = {r=0.0,g=1.0,b=1.0,a=0.25},
})

AddRoom("Tourist1_Room", {
	value = GROUND.FOREST,
	contents = {
		countstaticlayouts = {
			["Tourist1Layout"] = 1
		},
		distributepercent = 1.0,
		distributeprefabs = {
			ground_grass = 3,
		},
	},
	colour = {r=0.5,g=0.5,b=0.5,a=0.25},
})

AddRoom("Tourist2_Room", {
	value = GROUND.FOREST,
	contents = {
		countstaticlayouts = {
			["Tourist2Layout"] = 1
		},
		distributepercent = 1.0,
		distributeprefabs = {
			ground_grass = 3,
		},
	},
	colour = {r=0.5,g=0.5,b=0.5,a=0.25},
})

AddRoom("TouristBlood_Room", {
	value = GROUND.FOREST,
	contents = {
		countstaticlayouts = {
			["TouristBloodLayout"] = 1,
		},
		countprefabs = {
			heli_sign = 1
		},
		distributepercent = 1.0,
		distributeprefabs = {
			ground_grass = 3,
		},
	},
	colour = {r=0.5,g=0.5,b=0.5,a=0.25},
})

AddRoom("Camp4_Room", {
	value = GROUND.FOREST,
	tags={"ForceConnected"},
	contents = {
		countstaticlayouts = {
			Camp4Layout = 1
		},
		distributepercent = 1.0,
		distributeprefabs = {
			ground_grass=4,
			--houndbone=0.05,
			rock_flintless=0.5,
			marsh_tree=0.2,
			--marsh_bush=0.2,
		},
	},
	colour = {r=0.0,g=1.0,b=0.0,a=0.25},
})

AddRoom("Camp4_to_5_Room", {
	value = GROUND.GRASS,
	tags={"ForceConnected"},
	contents = {
		countstaticlayouts = {
			Camp3_to_4Layout = 1
		},
		distributepercent = 1.0,
		distributeprefabs = {
			ground_grass=4,
			--evergreen=1,
			--berrybush=0.2,
			--sapling=0.2,
			--houndbone=0.01,
			--pond=0.01,
		},
	},
	colour = {r=1.0,g=0.0,b=0.0,a=0.25},
})

AddRoom("Radio_Room", {
	tags={"ForceConnected"},
	value = GROUND.FOREST,
	contents = {
		countstaticlayouts = {
			RadioLayout = 1,
		},
		countprefabs = {
			heli_sign = 1,
		},
		distributepercent = 1.0,
		distributeprefabs = {
			ground_grass=4,
			rock1=0.2,
			rocks=0.3,
		},
	},
	colour = {r=1.0,g=1.0,b=0.0,a=0.25},
})

AddRoom("Camp5_Room", {
	value = GROUND.FOREST,
	tags={"RoadPoison"},
	contents = {
		countstaticlayouts = {
			Camp5Layout = 1
		},
		distributepercent = 1.0,
		distributeprefabs = {
			ground_grass=4,
			--houndbone=0.05,
			rock_flintless=0.5,
			marsh_tree=0.2,
			--marsh_bush=0.2,
		},
	},
	colour = {r=1.0,g=1.0,b=0.0,a=0.25},
})
